#define _CRT_SECURE_NO_WARNINGS

int hIndex(int* citations, int citationsSize) {
    int left = 0;
    int right = citationsSize - 1;
    while (left < right)
    {
        int mid = (right - left) / 2 + left;

        int count = citationsSize - mid;
        if (citations[mid] < count)
            left = mid + 1;
        else
            right = mid;
    }

    if (citations[left] == 0)
        return 0;
    else
        return citationsSize - left;
}